<template lang="pug">
  .clearfix
    Modal.lzw-modal-style-2(
      v-model="isShowCreateUpgradeNoticeModal"
      :title="createUpgradeNoticeModalTitle"
      fullscreen
    )
      Spin(size="large" fix v-if="createSpinShow")
      .h500
        Form.ivu-row(ref="formData" :model="formData" :rules="rules" :label-width="90")
          Row(type="flex" justify="start" :gutter="16")
            Col(span="8")
              FormItem(label="版本号：" prop="versionNumber")
                Input.input-has-border(v-model="formData.versionNumber" placeholder="请输入" clearable)
            Col(span="8")
              FormItem.ivu-form-item-required(label="发布时间：" :label-width="96")
                DatePicker.input-has-border(:value="formData.releaseTime" placeholder="请选择" type="date" @on-change="releaseTimeChange")
            Col(span="8")
              FormItem(label="启用")
                i-switch(v-model="formData.bulletinStatus" :true-value="1" :false-value="-1")
          FormItem.ivu-form-item-required(label="功能简述：" :label-width="96")
            Input.input-has-border(v-model="formData.bulletinSynopsis" type="textarea" placeholder="请输入" clearable)
          FormItem.ivu-form-item-required(label="内容：")
            editor(ref="editor" :value="formData.bulletinContent")
      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit('formData')") 确定
</template>

<script>
import BulletinApi from '@/api/Bulletin.api.js'
import Editor from '_c/editor'
export default {
  name: '',

  props: {
    createSpinShow: Boolean,
    formData: Object
  },

  components: {
    Editor
  },

  data () {
    return {
      isShowCreateUpgradeNoticeModal: false,
      createUpgradeNoticeModalTitle: '',
      basicDataId: '',
      rules: {
        versionNumber: [
          { required: true, message: '版本号不能为空', trigger: 'change' }
        ],
        releaseTime: [
          { type: 'date', required: true, message: '发布时间', trigger: 'change' }
        ]
      }
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    cancel () {
      this.isShowCreateUpgradeNoticeModal = false
    },

    show () {
      this.isShowCreateUpgradeNoticeModal = true
      this.$refs.formData.resetFields()
      console.log('点击是的show()')
    },

    // editorChange (html, text) {
    //   this.formData.bulletinContent = html
    // },
    releaseTimeChange (val) {
      this.formData.releaseTime = val
    },
    // 提交公告
    saveBulletin () {
      BulletinApi.SaveBulletin(this.formData).then(res => {
        console.log(res)
        if (res.data.success) {
          this.isShowCreateUpgradeNoticeModal = false
          this.$Message.success('发布成功')
          this.formData.bulletinContent = ''
          this.$emit('get-list')
        } else {
          this.$Message.error(res.data.message)
        }
      })
    },

    // 保存按钮
    handleSubmit (name) {console.log()
      this.formData.bulletinContent = this.$refs.editor.editor.txt.html()
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.saveBulletin()
        } else {
          this.$Message.warning('有必填项未填!')
        }
      })
    },
  }
}
</script>

<style lang="scss">
</style>
